<template>
  <div class="body">
    <i class="iconfont show">&#xe745;</i>
    <div class="first">
      <avatar size="40" :url="profile.avatar" shape="square"></avatar>
      <div class="text">
        亲爱的 <span>{{ profile.username }}</span> ,
        你已在iword学习 <span>{{birthday}}</span> 天
        <span><i class="iconfont">&#xe70f;</i></span>
      </div>
    </div>
    <div class="firstStatistics">
      <template v-if="this.finishBook!==0">
        <div class="main">
          <i class="iconfont">&#xe61c;</i>
          在过去的<span>{{birthday}}</span> 天里 你完成了 <span>{{finishBook}}</span> 课词书的背诵
        </div>
        <div class="ps">
          (ps:平均{{Total}}天完成一课)
        </div>
      </template>
      <template v-else>
        <div class="main">
          您当前还没有通关词书哦 请再接再励！！
          <i class="iconfont encourage">&#xe802;</i>
        </div>
        <RouterLink to="/" class="ps start">
          前往吧台选词 开始背诵
        </RouterLink>
      </template>
    </div>
    <div class="secondStatistics">
      <template v-if="this.Position!==0">
        <i class="iconfont">&#xe653;</i>
        您当前的词力得分为 <span>{{ Score }}</span> ，在本站排第<span>{{Position}}</span>名
      </template>
      <template v-else>
        只有开始至少一本词书的背诵才能进入排名哦!!!
      </template>
    </div>
  </div>
</template>
<script>
import avatar from '@/components/library/avatar.vue'
// 引入封装好的计算时间的模块
import { onlyDay } from '@/utils/daysApart'
// 引入获取统计成就
import { getStatistics } from '@/api/rank'
export default {
  name: 'my-statistics',
  components: {
    avatar
  },
  data () {
    return {
      profile: [],
      daynow: new Date(new Date().getTime()),
      finishBook: 0,
      Score: 0,
      Position: 0
    }
  },
  computed: {
    birthday () {
      return -onlyDay(this.daynow, this.profile.regday)
    },
    Total () {
      return Math.ceil(this.birthday / this.finishBook)
    }
  },
  created () {
    this.profile = this.$store.state.user.profile
    getStatistics().then((res) => {
      // console.log(res)
      this.finishBook = res.data.passbook
      this.Score = res.data.Score
      this.Position = res.data.Position
    })
  }
}
</script>
<style lang="less" scoped>
.body{
  border-radius: 10px;
  height: 260px;
  margin-left: 50px;
  width: 700px;
  background-color: #ffe66b7a;
  position: relative;
  .show{
    position:absolute;
    right: -10px;
    top: -20px;
    font-size: 36px;
    color: #3e86e5a7;
  }
  .first{
    display: flex;
    width: 600px;
    margin-top: 20px;
    margin-left: 60px;
    height: 40px;
    line-height: 40px;
    .text{
      text-indent: 20px;
      color: #666;
      span{
        color: #3e87e5;
      }
    }
  }
  .firstStatistics{
    text-indent: 20px;
    font-family: '钉钉进步体';
    background-color: #fcf6da;
    width: 600px;
    margin-top: 20px;
    margin-left: 60px;
    height: 60px;
    .main{
      height: 40px;
      line-height: 40px;
      font-size: 24px;
      .iconfont{
        font-size: 24px;
        color: rgb(155, 222, 54);
        font-weight: 600;
      }
      .encourage{
        color: #3e87e5;
        font-weight: 500;
      }
      span{
        color: rgb(155, 222, 54);
      }
    }
    .ps{
      color: #666666bb;
      height: 20px;
      line-height: 20px;
      font-size: 10px;
    }
    .start{
      margin-left: 20px;
      cursor: pointer;
      &:hover{
        color:#484848;
      }
    }
  }

  .secondStatistics{
    text-indent: 20px;
    font-family: '钉钉进步体';
    background-color: #fcf6da;
    width: 600px;
    margin-top: 20px;
    margin-left: 60px;
    height: 60px;
    line-height: 60px;
    font-size: 24px;
    span{
      color: #3e87e5
    }
    .iconfont{
      font-size: 24px;
      color: #3e87e5
    }
  }
}
</style>
